package org.springframework.social.kaixin.connect;

import java.util.Map;

import kx2_4j.KxSDK;

import org.springframework.social.oauth2.AccessGrant;
import org.springframework.social.oauth2.OAuth2Template;

public class KaixinOAuth2Template extends OAuth2Template {
	
	public KaixinOAuth2Template(String clientId, String clientSecret) {
		super(clientId, clientSecret, KxSDK.authorizationURL, KxSDK.accessTokenURLssl);
	}
	protected AccessGrant createAccessGrant(String accessToken, String scope, String refreshToken, Integer expiresIn, Map<String, Object> response) {
		/**
		 * too ugly, but in the constructor of AccessGrant, expiredTime is out of bound...
		 * which means it will expire every time because it always return a past time. 
		 */
		return new AccessGrant(accessToken, scope, refreshToken, expiresIn/1000);
	}

//	@Override
//	protected RestTemplate createRestTemplate() {
//		RestTemplate restTemplate = new RestTemplate(ClientHttpRequestFactorySelector.getRequestFactory());
//		FormHttpMessageConverter messageConverter = new FormHttpMessageConverter() {
//			public boolean canRead(Class<?> clazz, MediaType mediaType) {
//				return true;
//			}
//		};
//		restTemplate.getMessageConverters().add(messageConverter);
//		restTemplate.setMessageConverters(Collections.<HttpMessageConverter<?>>singletonList(messageConverter));
//		return restTemplate;
//	}
}
